技术经验 • dingxiao • 阅读数:2440 • 2018年7月16日 15:37
RPI3上使用java控制Bluetooth一直是自己想实现的功能,今天在外媒java bluetooth终于让我找到了方法,现将操作过程简单记录下。RPI3使用最新debian镜像(20170302)作为操作系统,并在3.5TFT上运行系统程序。
### 1.Step 1: Enable Bluetooth on the Raspberry Pi 3 ###
sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install piclone geany usb-modeswitch pi-bluetooth
sudo apt-get install python-pigpio python3-pigpio
sudo bluetoothctl
agent on
default-agent
scan on
You will see the MAC Addresses of nearby devices
Discovery started
[NEW] Controller XX:YY:ZZ:AA:BB:CC #Your Pi's MAC Address
[NEW] Device DD:EE:FF:GG:HH:II #Your Android's MAC Address
To pair the phone, replace MAC Address with your own
pair DD:EE:FF:GG:HH:II
[agent] Confirm passkey 123456 (yes/no): yes
[CHG] Device DD:EE:FF:GG:HH:II Modalias: bluetooth:xxxx
[CHG] Device DD:EE:FF:GG:HH:II UUIDs
<bunch of numbers>
[CHG] Device DD:EE:FF:GG:HH:II Paired: Yes
Pairing successful
[CHG] Device DD:EE:FF:GG:HH:II Connected: No
[CHG] Device DD:EE:FF:GG:HH:II Trusted: Yes
sudo nano /etc/systemd/system/dbus-org.bluez.service
ExecStart=/usr/lib/bluetooth/bluetoothd -C
ExecStartPost=/usr/bin/sdptool add SP
sudo rfcomm watch hci0
cat /dev/rfcomm0
!!!需要注意的是java测试代码必须连接手机APP,并在“sudo rfcomm watch hci0”“cat /dev/rfcomm0”和指令执行之后运行。